package org.jetlinks.community.device.entity;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import org.hswebframework.ezorm.rdb.mapping.annotation.Comment;
import org.hswebframework.web.api.crud.entity.GenericEntity;
import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;

import javax.persistence.Column;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;

@Getter
@Setter
@Table(name = "s_region_dev")
public class RegionDeviceEntity extends GenericEntity<String> {

    @Comment("区域ID")
    @Column(name = "region_id", nullable = false, length = 64)
    @Schema(description = "区域ID")
    private String regionId;

    @Comment("区域名称")
    @Column(name = "region_name", nullable = false, length = 128)
    @NotBlank
    @Schema(description = "区域名称")
    private String regionName;

    @Comment("设备ID")
    @Column( name = "device_id", nullable = false, length = 64)
    @Schema(description = "设备ID")
    @NotBlank
    private String deviceId;

    @Comment("设备名")
    @Column(name = "device_name", nullable = false,length = 128)
    @Schema(description = "设备名")
    private String deviceName;


    public RegionDeviceEntity() {
    }

    public void generateId() {
        if (StringUtils.isEmpty(this.getId())) {
            String id = DigestUtils.md5DigestAsHex(String.format("%s-%s", this.regionId, this.deviceId).getBytes());
            this.setId(id);
        }

    }


    public String getRegionId() {
        return this.regionId;
    }

    public String getRegionName() {
        return this.regionName;
    }

    public String getDeviceId() {
        return this.deviceId;
    }

    public String getDeviceName() {
        return this.deviceName;
    }

    public void setRegionId(String regionId) {
        this.regionId = regionId;
    }

    public void setRegionName(String regionName) {
        this.regionName = regionName;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public void setDeviceName(String deviceName) {
        this.deviceName = deviceName;
    }

}
